package com.xiaoge.libraryuse.interface_call_back;

import android.os.Bundle;
import android.widget.ListView;

import com.xiaoge.basedevlibrary.base.GuoBaseActivity;
import com.xiaoge.basedevlibrary.utils.ToastUtil;
import com.xiaoge.libraryuse.R;

import java.util.ArrayList;
import java.util.List;

public class InterfaceCallBackActivity extends GuoBaseActivity implements OnItemBtnClickListener{

    private ListView lv;
    private List<String> mDatas;
    private CallBackAdapter mAdapter;
    private InterfaceCallBackActivity mCtx;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_interface_call_back);
        this.mCtx = this;
        initView();
        initData();
    }

    private void initView() {
        lv = (ListView) findViewById(R.id.lv);
    }

    private void initData() {
        mDatas = new ArrayList<String>();
        for (int i = 0; i < 15; i++) {
            mDatas.add("我是第" + (i + 1) + "个元素");
        }
        mAdapter = new CallBackAdapter(this, mDatas);
        lv.setAdapter(mAdapter);
        // 订阅接口回调
        mAdapter.setOnItemBtnClickListener(this);
    }

    @Override
    public void onItemBtnClick(int position, String item, List<String> datas) {
        ToastUtil.showToast(mCtx,"点击了：" + datas.get(position));
    }
}
